from lxml import etree

tree = etree.parse('learn.html')
# result = tree.xpath('/html')
# result = tree.xpath('/html/body/ol/li/a[@href="dapao"]/text()')  # [@xxx="xxx"] 为属性的筛选

ol_li_list = tree.xpath("/html/body/ol/li")
for li in ol_li_list:
    # 从每一个li中提取到文字信息
    result = li.xpath("./a/text()")   # 在li中继续去寻找，相对查找  ./为当前节点，相对查找
    print(result)

    # 查找a标签里面href的值
    result_s = li.xpath("./a/@href")  # 拿到属性的值：@属性
    print(result_s)


print(tree.xpath('/html/body/ul/li/a/@href'))
